<template>
  <div class="clas_All">
    <el-form
      class="const_top"
      :model="queryParams"
      ref="form"
      size="small"
      :inline="true"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item prop="relateId" style="">
            <el-select
              v-model="byMonth.relateId"
              placeholder="请选择部门"
              clearable
              @change="deptChange"
            >
              <el-option
                v-for="dict in deptOptions"
                :key="dict.relateId"
                :label="dict.label"
                :value="dict.relateId"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="createdTime" style="">
            <el-date-picker
              clearable
              v-model="queryParams.createdTime"
              type="month"
              placeholder="选择月"
              @change="createdTimeChange"
              :disabled="mouday"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item prop="pandianCode" style="">
            <el-select
              v-model="queryParams.pandianCode"
              placeholder="1号至10号"
              clearable
              :disabled="mount"
            >
              <el-option
                v-for="dict in NewDropDownList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuery"
              >查询
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <el-col></el-col>
      <el-col>
        <el-table :data="tableData">
          <el-table-column align="center" label="序号" type="index" width="50">
          </el-table-column>
          <el-table-column label="诊断类型" prop="type" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.type == 1">期初少盘</div>
              <div v-if="scope.row.type == 2">期初多盘</div>
              <div v-if="scope.row.type == 3">实际成本为负</div>
            </template>
          </el-table-column>
          <el-table-column
            label="描述"
            prop="desc"
            align="center"
          ></el-table-column>
          <el-table-column
            label="涉及金额/元"
            prop="amout"
            align="center"
          ></el-table-column>
          <el-table-column
            label="涉及部门/个"
            prop="deptNum"
            align="center"
          ></el-table-column>
          <el-table-column
            label="涉及原料/个"
            prop="stapNum"
            align="center"
          ></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <div>
                <el-button
                  size="mini"
                  type="text"
                  @click="Openvisition(scope.row)"
                  >部门诊断详情</el-button
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-dialog
      @close="onClose"
      width="60%"
      title=""
      :visible.sync="semiFinishedVisible"
    >
      <el-row :gutter="15">
        <el-form ref="elForm" size="medium" label-width="100px">
          <el-col :span="24"> </el-col>
          <el-table :data="tableDataOne">
            <el-table-column align="center" prop="deptName" label="班组">
            </el-table-column>
            <el-table-column
              align="center"
              prop="amout"
              label="本期虚减、上期虚增利润/元"
            >
            </el-table-column>
            <el-table-column align="center" prop="stapNum" label="涉及原料/种">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <div>
                  <el-button
                    size="mini"
                    type="text"
                    @click="DelTable(scope.row)"
                    >部门原料明细</el-button
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>

          <el-row>
            <el-col :span="12" class="btn"> </el-col>
            <el-col :span="12" class="btn">
              <el-button
                type="primary"
                size="medium"
                round
                @click="semiFinishedVisible = false"
              >
                关闭
              </el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import {
  stapprolossDiagnosis,
  infostapprolossDiagnosis,
} from "@/api//system/cost.js";
import { getPanDianCode, FindShopBom } from "@/api/system/stock";
export default {
  data() {
    return {
      queryParams: {},
      semiFinishedVisible: false,
      examineOption: [],
      tableData: [],
      tableDataOne: [],
      deptOptions: [],
      DropDownList: [],
      NewDropDownList: [],
      byMonth: {},
      mouday: true,
      mount: true,
      defaultProps: {
        children: "children",
        label: "label",
      },
      form: {},
    };
  },
  created() {
    FindShopBom().then((res) => {
      // console.log(res);
      if (res.code == 200) {
        let ovj = res.data.filter((ite) => {
          if (ite.relateId !== null) {
            delete ite.children;
            return ite;
          }
        });
        if (ovj.length > 1) {
          this.mouday = true;
        }
        this.deptOptions = ovj;
      }
    });
  },
  methods: {
    OpenClcik(v) {},
    handleQuery() {
      this.getList();
    },
    handleRowClick() {},
    onClose() {},
    DelTable(v) {
      this.$router.push({
        // pandianCode=BU1010010024P20240229S4&shopCode=76450932&stapType=BU101001002400201
        path: "/SubclassCategory",
        query: {
          pandianCode: this.queryParams.pandianCode,
          deptCode: v.deptCode,
          stapCode: v.deptCode,
        },
      });
    },
    getList() {
      stapprolossDiagnosis({ pandianCode: this.queryParams.pandianCode }).then(
        (res) => {
          if (res.code == 200) {
            this.tableData = res.data;
          }
        }
      );
      // stapProlossAnalysDetail;
    },
    createdTimeChange(v) {
      let data = new Date(v);
      let y = data.getFullYear();
      let m = data.getMonth() + 1;
      this.byMonth.pandianData = y + String(m).padStart(2, "0");
      getPanDianCode(this.byMonth).then((res) => {
        if (res.code == 200) {
          this.DropDownList = res.data;
          this.NewDropDownList = [];
          this.DropDownList.forEach((element) => {
            let label =
              new Date(element.startTime).getDate() +
              "号-" +
              new Date(element.endTime).getDate() +
              "号";
            this.NewDropDownList.push({
              value: element.pandianCode,
              label: label,
            });
          });
          if (res.data != []) {
            this.mount = false;
          }
        }
      });
    },
    deptChange(v) {
      if (v) {
        this.mouday = false;
      } else {
        this.mouday = true;
      }
    },
    Openvisition(v) {
      infostapprolossDiagnosis({
        pandianCode: this.queryParams.pandianCode,
        type: v.type,
      }).then((res) => {
        if (res.code == 200) {
          this.semiFinishedVisible = true;
          this.tableDataOne = res.data;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.clas_All {
  margin: 20px;
}
</style>
